
function Get-CMAdvertisement
{
<#
.Synopsis
    Returns an advertisement, or all instances of an advertisement.
.Description
    Returns an advertisement, or all instances of an advertisement.
.Parameter SiteServerName 
    ConfigMgr Site Server Name
.Parameter AdvertisementID
    Enter AdvertisementID    
.Parameter Credential 
    Enter Alternate Credentials if required
.Example
    Get-CMAdvertisement
.Example
    Get-CMAdvertisement MYTESTLABServer
        Returns all instances of the SMS_Advertisement Class on MYTESTLABServer
.Example
    Get-CMAdvertisement MYTESTLABServer LAB20012 
        Returns advertisement LAB20012 on MYTESTLABServer
.Example
    Get-CMAdvertisement MYTESTLABServer LAB20012 get-credential
        Prompts for credentials
.Example
    Get-CMAdvertisement MYTESTLABServer LAB20012 $Cred
        uses credentials in $Cred
.Outputs
    Returns either an instance, or multiple instances from the SMS_Advertisement Class
.Link
    http://msdn.microsoft.com/en-us/library/cc146108.aspx
.Notes
 NAME:      Get-CMAdvertisement
 AUTHOR:    Greg Ramsey
 LASTEDIT:  08/07/2009 00:39:05
#Requires -Version 2.0
#>

[CmdletBinding(
    SupportsShouldProcess=$False,
    SupportsTransactions=$False, 
    ConfirmImpact="None",
    DefaultParameterSetName="")]
param(
[Parameter(Position=0)]
[String]$ComputerName="." ,

[Parameter(Position=1)]
[String]$AdvertisementID=$Null,

[Parameter(Position=2)]
[String]$Filter=$Null ,

[Parameter(Position=3)]
$Credential
)

Begin
{
}#Begin

Process
{
    get-cmobject -class SMS_Advertisement -ComputerName $ComputerName -Filter $Filter -Credential $Credential | ? {$_.AdvertisementID -like ($AdvertisementID + "*")}
}#Process

End
{
}#End
}


function New-CMAdvertisement
{
<#
.Synopsis
    Creates a new ConfigMgr Advertisement.
.Description
    Creates a new ConfigMgr Advertisement.
.Parameter SiteServerName 
    ConfigMgr Site Server Name
.Parameter PackageID
    Enter PackageID
.Parameter ProgramName
    Enter ProgramName    
.Parameter AdvertisementName
    Enter Advertisement Name
.Example
    New-CMAdvertisement
        Prompts for required information.
.Example
    New-CMAdvertisement MYTESTLABServer LAB00023 "Silent Install" "Foo Advert" "LAB00004"
        Creates a new Advertisement named "Foo Advert" for CollectionID=LAB00004 and PackageID=LAB00023 and Program Name "Silent Install on the site server MYTESTLABServer
.Outputs
    Returns the new Program instance from the SMS_Program Class
.Link
    http://msdn.microsoft.com/en-us/library/cc146108.aspx
.Notes
 NAME:      New-CMAdvertisement
 AUTHOR:    Greg Ramsey
 LASTEDIT:  08/07/2009 00:39:05
#Requires -Version 2.0
#>

[CmdletBinding(
    SupportsShouldProcess=$False,
    SupportsTransactions=$False, 
    ConfirmImpact="None",
    DefaultParameterSetName="")]
param(
[Parameter(Position=0)]
[String]$ComputerName="." ,

[Parameter(Position=1, Mandatory=$true, HelpMessage="Enter PackageID")]
[String]$PackageID ,

[Parameter(Position=2, Mandatory=$true, HelpMessage="Enter Program Name")]
[String]$ProgramName=$Null ,

[Parameter(Position=3, Mandatory=$true, HelpMessage="Enter Advertisement Name")]
[String]$AdvertisementName=$Null,

[Parameter(Position=4, Mandatory=$true, HelpMessage="Enter CollectionID")]
[String]$CollectioNID=$Null 
 
)

Begin
{
}#Begin

Process
{
    $oSite = Connect-CMProvider -Computer $ComputerName -Credential $Credential
    $NS = "Root\SMS\Site_" + $oSite.SiteCode
    
      $arguments = @{PackageID = $PackageID; ProgramName = $ProgramName; CollectionID = $CollectionID; AdvertisementName = $AdvertisementName}
      $newAdvert = set-wmiinstance -class SMS_Advertisement -arguments $arguments -computername $ComputerName -namespace $NS -ErrorAction SilentlyContinue
      $newAdvert   
        
    }#Process

End
{
}#End
}